package 力扣_算法题综合.高频面试算法;

import java.math.BigInteger;

/**
 * @author zx
 * @create 2022-09-14 22:40
 */
public class 计算2的1000次方 {
    /**
     * 用数组计算2^1000
     * @param args
     */
    public static void main(String[] args) {
        int[] arr = new int[1000];
        int i = 0, j = 0, k = 0, len = 1;
        int temp;
        arr[0] = 1;
        while (i < 1000) {
            for (j = len - 1; j >= 0; j--) {
                temp = arr[j];
                temp *= 2;
                if (temp < 10) {
                    arr[j] = temp;
                } else {
                    arr[j] = temp % 10;
                    arr[j + 1] = arr[j + 1] + temp / 10;

                    if (j + 1 == len)
                        len++;

                    for (k = j + 1; k < len - 1; k++) {
                        if (arr[k] > 10) {
                            arr[k] = arr[k] % 10;
                            arr[k + 1] = arr[k + 1] + arr[k] / 10;

                            if (k + 1 == len)
                                len++;

                        } else
                            break;
                    }
                }
            }
            i++;
        }
        System.out.println(len);
        for (i = len - 1; i >= 0; i--) {
            System.out.print(arr[i]);
        }
        System.out.println();
    }

    /**
     * Java API
     */
    public static void main2(String[] args) {
        BigInteger a = new BigInteger("2");
        BigInteger res = a.pow(1000);
        System.out.println(res);
    }
}
